import ctypes

lib = ctypes.cdll.LoadLibrary('libmath.dylib')

lib.e_series.restype = ctypes.c_double
lib.e_series.argtypes = [ctypes.c_long]
lib.e_limit.restype = ctypes.c_double
lib.e_limit.argtypes = [ctypes.c_double]

lib.pi_series.restype = ctypes.c_double
lib.pi_series.argtypes = [ctypes.c_long]
lib.pi_gauss_legendre.restype = ctypes.c_double
lib.pi_gauss_legendre.argtypes = [ctypes.c_double]

print "x", "e (series)", "e (limit)"
for x in range(50):
    print x, lib.e_series(x), lib.e_limit(x)

print "x", "e (limit)"
print 1000000, lib.e_limit(1000000)

print "GCD_REC(1071, 462) = ", lib.gcd_rec(1071, 462)
print "GCD_ITE_DIV(1071, 462) = ", lib.gcd_ite_div(1071, 462)
print "GCD_ITE_SUB(1071, 462) = ", lib.gcd_ite_sub(1071, 462)

lib.factorial_rec.restype = ctypes.c_long
lib.factorial_rec.argtypes = [ctypes.c_long]
lib.factorial_ite.restype = ctypes.c_long
lib.factorial_ite.argtypes = [ctypes.c_long]
lib.factorial_gamma.restype = ctypes.c_double
lib.factorial_gamma.argtypes = [ctypes.c_double]

for x in range(21):
    print x, "!", lib.factorial_rec(x), lib.factorial_ite(x),
    print lib.factorial_gamma(x)

for x in range(10):
    print x, lib.pi_series(x)

for x in [1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001]:
    print x, lib.pi_gauss_legendre(x)
